package com.tianqu.tms.www.car.controller;

import java.util.List;
import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsController;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.entity.MarketCarHandleInfo;
import com.tianqu.tms.entity.TransferAcceptedInfo;

/**
 * @author zhangxueliang
 * 高级搜索车辆过户进度查看 controller
 */
public class CarSearchTransferHistoryListTopController extends TmsController{
	private Logger logger = Logger.getLogger(CarSearchTransferHistoryListTopController.class);
	public static final String THISTORYLIST = "tHistoryList"; 
	@SuppressWarnings("unchecked")
	@Override
	public void execute(UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TxController controller = TxController.getTxController();

		// 添加事务提交异常捕获
		try {
			controller.begin();
			String serial = "";
			String basicCarId = (String)uc.getAttribute("serial");//基本信息详细页中的库存表中的serial
			MarketCarHandleInfo entity = MarketCarHandleInfo.getInstance();
		
			//根据库存表中的serial载入过户信息表中serial
			TransferAcceptedInfo transferAcceptedInfo = TransferAcceptedInfo.getInstance();
			transferAcceptedInfo = transferAcceptedInfo.getTransferBybasicCarId(basicCarId);
			serial = transferAcceptedInfo.getSerial();
			List<MarketCarHandleInfo> handleList = entity.findHandleInfoBySerial(basicCarId);
			uc.setAttribute(THISTORYLIST, handleList);
			controller.commit();
			
		} catch (Exception e) {
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
			// 系统异常
			if (e instanceof TmsException) {
				throw e;
			}
			throw new TmsException(TmsException.DB_TXCRROR, e);
		}
		logger.debug(this.getClass().getName() + "#execute was completed.");
	}
	
}


